package com.aloda.mapper;

import com.aloda.pojo.dto.BookPageDTO;
import com.aloda.pojo.dto.BookQueryDTO;
import com.aloda.pojo.dto.UserSafetyDTO;
import com.aloda.pojo.entity.Book;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookMapper {
    /**
     * 根据给定数量获取最新图书
     * @param recommendBookNums
     * @return
     */
    @Select("SELECT * FROM book where book_status !='3' order by book_uploadtime DESC limit #{num}")
    @Results(id = "bookMap",value = {
            //id字段默认为false，表示不是主键
            //column表示数据库表字段，property表示实体类属性名。
            @Result(id = true,column = "book_id",property = "id"),
            @Result(column = "book_name",property = "name"),
            @Result(column = "book_isbn",property = "isbn"),
            @Result(column = "book_press",property = "press"),
            @Result(column = "book_author",property = "author"),
            @Result(column = "book_pagination",property = "pagination"),
            @Result(column = "book_price",property = "price"),
            @Result(column = "book_uploadtime",property = "uploadTime"),
            @Result(column = "book_status",property = "status"),
            @Result(column = "book_borrower",property = "borrower"),
            @Result(column = "book_borrowtime",property = "borrowTime"),
            @Result(column = "book_returntime",property = "returnTime")
    })
    List<Book> selectNewBookByNum(int recommendBookNums);

    /**
     * 分页查询图书
     * @param bookPageDTO
     * @return
     */
    Page selectPage(BookPageDTO bookPageDTO);

    /**
     * 新增图书
     * @param book
     */
    void insert(Book book);

    /**
     * 根据id查询图书
     * @param id
     * @return
     */
    Book selectById(Integer id);

    /**
     * 更新图书信息
     * @param book
     */
    void update(Book book);

    /**
     * 查询当前用户借阅的书
     *
     * @return
     */
    Page selectCurrentBorrowBookPage(BookQueryDTO bookQueryDTO);

    /**
     * 查找管理员借阅的书和所有归还中待确认的书
     * @param
     * @param
     * @return
     */
    Page selectAdminBookPage(BookQueryDTO bookQueryDTO);
}
